package com.usernet.product.dao;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;

import com.usernet.product.comm.BaseDao;
import com.usernet.product.utils.DateUtils;
import com.usernet.product.utils.Page;
import com.usernet.product.utils.PageResult;

public class ErrorDao extends BaseDao {

	@SuppressWarnings("unchecked")
	public PageResult<com.usernet.product.entity.Error> getAllByPage(Page page) {
		String hql = "from Error order by id";
		return super.getAllByPageAndHql(page, hql);
	}

	@SuppressWarnings("unchecked")
	public PageResult<com.usernet.product.entity.Error> getAllByParams(
			Page page, String softName, String time) {
		Map<String, Timestamp> map = null;
		String hql = "from Error where 1=1";
		if (softName != null && !"".equals(softName.trim())) {
			hql += " and (software.name like '%" + softName
					+ "%' or software.pinyin like '%" + softName + "%')";
		}
		if (time != null && !"".equals(time.trim())) {
			hql += " and time>=:beginTime and time<=:endTime";
			Timestamp beginTime = DateUtils.stringToTimestampBegin(time);
			Timestamp endTime = DateUtils.stringToTimestampEnd(time);
			map = new HashMap<String, Timestamp>();
			map.put("beginTime", beginTime);
			map.put("endTime", endTime);
		}
		hql += " order by id";
		return super.getAllByPageAndHql(page, hql, map);
	}
}
